package com.sokal.easycare.modules.kpoint.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import com.sokal.easycare.common.persistence.Page;
import com.sokal.easycare.common.service.CrudService;
import com.sokal.easycare.common.utils.FastDFS.FastDFSClient;
import com.sokal.easycare.modules.kpoint.dao.KPointFileDao;
import com.sokal.easycare.modules.kpoint.entity.KPointFile;
import com.sokal.easycare.modules.kpoint.entity.KPointMain;
import com.sokal.easycare.modules.product.entity.product.ProProductFile;

/**
 * 体验店附件Service
 * @author lihaipei
 * @version 2017-03-19
 */
@Service
@Transactional(readOnly = true)
public class KPointFileService extends CrudService<KPointFileDao, KPointFile> {
	
	public KPointFile get(String id) {
		KPointFile kPointFile = super.get(id);
		return kPointFile;
	}
	
	public List<KPointFile> findList(KPointFile kPointFile) {
		return super.findList(kPointFile);
	}
	
	public Page<KPointFile> findPage(Page<KPointFile> page, KPointFile kPointFile) {
		return super.findPage(page, kPointFile);
	}
	
	@Transactional(readOnly = false)
	public void save(KPointFile kPointFile) {
		super.save(kPointFile);
	}

	@Transactional(readOnly = false)
	public void saveFiles(MultipartFile exprStoreFile, String exprStoreId) {
		try {
			KPointMain kPointMain = new KPointMain();
			kPointMain.setId(exprStoreId);
			
			KPointFile kPointFile = new KPointFile();
			kPointFile.setFileUrl(FastDFSClient.uploadFile(exprStoreFile, exprStoreFile.getOriginalFilename()));
			kPointFile.setFileName(exprStoreFile.getOriginalFilename());
			kPointFile.setFileType(ProProductFile.FILE_TYPE_SINGLE_IMAGE);
			kPointFile.setkPointMain(kPointMain);
			
			super.save(kPointFile);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(KPointFile kPointFile) {
		super.delete(kPointFile);
	}

	@Transactional(readOnly = false)
	public void updateSort(KPointFile kPointFile) {
		dao.updateSort(kPointFile);
	}
	
}